package com.riant.day03.demo03;
import java.io.File;
import java.io.FileOutputStream;
import java.nio.charset.Charset;

/**
 * @Classname TestFile2
 * @Description TODO
 * @Date 2021/3/5 23:18
 * @Created by 张斌
 */
public class TestFile2 {
    public static void main(String[] args) {
        File file=new File("day01\\src\\main\\java\\com\\riant\\day03\\demo03\\b.txt");
        testFile2(file);
    }

    public static void testFile(File file)  {
        try {
            FileOutputStream fos = new FileOutputStream(file);
            String str="abcd";
            fos.write(str.getBytes());
            fos.close();
        }catch (Exception e){
            e.printStackTrace();
        }
    }
    public static void testFile2(File file)  {
        try {
            FileOutputStream fos = new FileOutputStream(file);
            String str="我是张三";
            fos.write(str.getBytes(Charset.forName("utf-8")));
            fos.close();
        }catch (Exception e){
            e.printStackTrace();
        }
    }

}
